package gov.nist.ssd.swqb.gui;

import java.awt.Component;
import javax.swing.JOptionPane;
import com.ezware.dialog.task.TaskDialogs;
import javax.swing.JFrame;

/**
 *
 * @author Benjamin Herbomez
 */
public class ErrorDisplayer {

    private static ErrorDisplayer instance = null;
    private static JFrame parent = null;
    
    private ErrorDisplayer() {
    }
    
    public static ErrorDisplayer getInstance(){
        if(instance == null)
            instance = new ErrorDisplayer();
        return instance;
    }

    public void displayError(String msg) {
        TaskDialogs.error(parent,"Error", msg);
    }
    
    public void displayError(String msg, JFrame f) {
        TaskDialogs.error(f,"Error", msg);
    }

    public void displayError(String msg, String title) {
        TaskDialogs.error(parent,title, msg);
    }
    
    public void displayError(String msg, String title, JFrame f) {
        TaskDialogs.error(f,"Error", msg);
    }
    
    public static void setDefaultParentFrame(JFrame f){
        parent = f;
    }
    
    public void displayError(Exception e){
        TaskDialogs.showException(e);
    }
    public void displayError(String msg, Exception e){
        Exception ex = new Exception(msg);
        ex.setStackTrace(e.getStackTrace());
        TaskDialogs.showException(ex);
    }

    public void displayWarning(String msg) {
        TaskDialogs.isConfirmed(parent, "Warning", msg);
    }

    public void displayWarning(String msg, JFrame f) {
        TaskDialogs.isConfirmed(f, "Warning", msg);
    }
    
    public void displayWarning(String msg, String title) {
        TaskDialogs.isConfirmed(parent, title, msg);
    }
    
    public void displayWarning(String msg, String title, JFrame f) {
        TaskDialogs.isConfirmed(f, title, msg);
    }

    public int askForConfirmWarn(String msg, String title, Object[] options, int def) {
        return JOptionPane.showOptionDialog(null, msg, title, JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE, null, options, options[def]);
    }
    
    public int askForConfirmWarn(String msg, String title, Object[] options, int def, Component p) {
        return JOptionPane.showOptionDialog(p, msg, title, JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE, null, options, options[def]);
    }
}
